package org.codert.codertadmin.domain;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: TanJingyu
 * @create: 2021-08-05 10:16
 **/
@Getter
@Setter
@Accessors(chain = true)
public class Goods {
    private Integer id;
    private String title;
    private Map<String, Object> spec;
    public static final ObjectMapper MAPPER = new ObjectMapper();

    public String getSpec() throws JsonProcessingException {
        return MAPPER.writeValueAsString(spec);
    }

    public Goods setSpec(String spec) {
        try {
            this.spec = MAPPER.readValue(spec, HashMap.class);
            return this;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return this;
        }
    }
}
